/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.dinotrack.domain;

import org.hibernate.SQLQuery;
import org.hibernate.Session;

/**
 *
 * @author alquad
 */
public class DinotrackerSQL {
    
    Session session = null;

    public DinotrackerSQL() {
        session = HibernateUtil.getSessionFactory().getCurrentSession();
    }

    public boolean registrarDinotracker(Persona persona) {
        try {
            
            Estado estado = new EstadoSQL().getEstado("Habilitado");
            
            session.beginTransaction();
            
            SQLQuery reg = session.createSQLQuery("call dinotracker_registrar(?, ?, ?)");
            reg.setParameter(0, persona.getUsuario().getUsuario());
            reg.setParameter(1, persona.getIdPersona());
            reg.setParameter(2, estado.getIdEstado());
            reg.executeUpdate();
            
            session.getTransaction().commit();

            return true;

        } catch (Exception e) {
            e.printStackTrace();
        }

        return false;
    }
    
}
